<template>
  <div id="app">
    <!-- 设置顶部导航栏 -->
    <mt-header title="药 品 库 存">
      <mt-button icon="back" @click="goBack" slot="left">返回</mt-button>
      <mt-button slot="right" @click="goHome">
        <img
          src="../../assets/images/home.png"
          height="20"
          width="20"
          slot="icon"
          style="margin-top: 5px"
        />
      </mt-button>
    </mt-header>

    <!-- 搜索 -->
    <van-search
      v-model="searchTxt"
      show-action
      placeholder="请输入药品名称"
      @clear="onCancel"
      @search="onSearch"
      @cancel="onCancel"
    />

    <!-- 列表数据区域 -->
    <div class="main">
      <!-- 数据列表区域 -->
      <van-collapse v-model="activeNames">
        <van-collapse-item
          v-for="(item, index) in drugList"
          :key="index"
          :title="item.name"
          :value="'数量' + item.num"
          :label="'药品价格：' + item.sellingPrice"
        >
          <p class="effecct">药品有效期至：{{ item.validDate }}</p>
          <p class="effecct">药品批次：{{ item.batchNumber }}</p>
        </van-collapse-item>
      </van-collapse>
    </div>

    <!-- 底部添加按钮 -->
    <div class="btn">
      <van-button
        type="primary"
        size="large"
        block
        color="linear-gradient(to right, #00b894, #55efc4)"
        @click="addDrug"
        >添加药品</van-button
      >
      <van-button
        type="primary"
        size="large"
        block
        color="linear-gradient(to right, #5352ed, #3742fa)"
        @click="addDictionary"
        >新增药品类型</van-button
      >
    </div>
  </div>
</template>

<script>
// import { Toast } from "vant";
export default {
  name: "DrugManage",

  data() {
    return {
      //药品库存列表数据
      drugList: [],
      activeNames: ["1"],
      //搜索框的文字
      searchTxt: null,
    };
  },

  mounted() {},
  created() {
    this.getList();
  },
  methods: {
    goBack() {
      this.$router.push({
        path: "./DrugMain",
      });
    },
    goHome() {
      this.$router.push({
        path: "./index",
      });
    },
    //获取药品库存
    getList() {
      this.$http
        .get("drug", {})
        .then((res) => {
          console.log(res);
          this.drugList = res.data.data;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    onSearch() {
      this.$http
        .get("drug/page", {
          params: {
            pageSize: 100,
            pageNum: 1,
            name: this.searchTxt,
          },
        })
        .then((res) => {
          // console.log(res);
          this.drugList = res.data.data.records;
        });
      // console.log(this.searchTxt);
    },
    onCancel() {
      this.getList();
    },
    //添加药品
    addDrug() {
      this.$router.push({
        path: "./addDrug",
      });
    },
    //添加药品字典点击
    addDictionary(){
      this.$router.push({
        path: "./record",
      });
    }
  },
};
</script>

<style lang="less" scoped>
.main {
  margin-bottom: 52px;
}
.btn {
  display: flex;
  width: 100%;
  position: fixed;
  bottom: 0;
}
</style>